package puzzle.projecteuler.p200;

public class Problem137C {

	/**
	 * A(x) = -x/(x^2 + x - 1)
	 *     A(x) = n, x是有理数
	 * <=> 5n^2 + 2n + 1 = m^2
	 * <=> (5n+1)^2 + 4 = 5m^2
	 * 
	 * X^2 - 5Y^2 = -4
	 * X + Y*sqrt(5) = (1 + 1*sqrt(5))*((7+3*sqrt(5))/2)^n
	 * => X = (7X + 15Y)/2
	 *    Y = (3X + 7Y)/2
	 * @param args
	 */
	public static void main(String[] args) {
		
		long x = 1;
		long y = 1;
		int c = 15;
		long n = 0;
		while (c > 0) {
			long tmp = x;
			x = (7*x + 15*y)/2;
			y = (3*tmp + 7*y)/2;
			c --;
			n = (x-1)/5;
		}
		System.out.println(n);
	}

}
